package model;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.ItemCollection;
import model.Item;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * 
 * @author Martin Mohr Pedersen
 */
public class ItemCollectionTest {

	private ItemCollection collection;
        private Item item1;
        private Item item2;       
                
	public ItemCollectionTest() {
	}

	@BeforeClass
	public static void setUpClass() throws Exception {
	}

	@AfterClass
	public static void tearDownClass() throws Exception {
	}

	@Before
	public void setUp() {
		collection = ItemCollection.getInstance();
                item1 = new Item();
		item1.setItemNo("1");
		item2 = new Item();
		item2.setItemNo("2");
	}

	@After
	public void tearDown() {
	}

	/**
	 * Test of getItem method, of class ItemCollection.
	 */
	@Test
	public void testGetItem() {

		try {
			collection.addItem(item1);
			collection.addItem(item2);
		} catch (DuplicateItemIdentifierException e) {
			e.printStackTrace();
		}

		Item item = collection.getItem("1");
		assertSame(item1, item);

	}
        
        @Test (expected=DuplicateItemIdentifierException.class)
        public void testDuplicateItemNo() throws DuplicateItemIdentifierException {
        
            collection.addItem(item1);
            item2.setItemNo("1");
            collection.addItem(item2);
            fail();                        
        }
}
